/* FILE : XWindow.c */

#ifdef HAVE_CONFIG_H
# include <config.h>
#endif

#include <stdio.h>
#include <X11/Xlib.h>

#include "XWindow.h"

void
get_caret_point(Window w, XPoint auxpoint, int *x, int *y)
{
        //GdkPoint p;
        XWindowAttributes attr;
        int client_x, client_y;
	Window dummy;
	Display *display = XOpenDisplay(NULL);

        *x = *y = 0;
	if (!display)
		return;
 
        XGetWindowAttributes(display, w, &attr);

        XTranslateCoordinates(display, w, attr.root, 0, 0, &client_x, &client_y, &dummy);

        if (auxpoint.y != -1) {  // -1 is invalid
                *x = client_x + auxpoint.x;
                *y = client_y + auxpoint.y;
        } else {
                *x = client_x;
                *y = client_y + attr.height;
        }
}
